package com.ruoyi.merchant.config;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.merchant.util.H002ModelCmdEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ConsumerListener {

    @Autowired
    private WebSocket webSocket;

    /**
     * 业务报警
     * @param message
     */
    @KafkaListener(topics = H002ModelCmdEnum.ALARM001)
    public void ALARM001Handler(String message) {
        log.info("收到站内业务报警：{}",message);
        JSONObject jsonObject = JSONObject.parseObject(message);
        JSONObject data = jsonObject.getJSONObject("data");
        if (data == null){
            log.error("消息体数据为空，不能确定发送对象");
        }else {
            String appUserId = data.getString("appUserId");
            webSocket.pushMessage(appUserId,message);
        }

    }

}
